import store from '@/store' 
export const hasRole = { 
    install: (app) => 
    { app.directive('hasRole', 
    { mounted(el, binding) {
                 // roles的值，应为string数组，存放角色列表  例子：['add','edit','del']         
                 // 也可以根据自己的逻辑修改         
                 const roles = store.getters['user/permissions'] //['edit','add']   
                 const value = binding.value  
                 if(roles[0]==='*:*:*'){
                    return true
                }else{
                    let flag = value.filter((v)=>{   
                        return roles.indexOf(v)!=-1          
                    }) 
                    if (flag.length<=0) {           
                        if (!el.parentNode) {             
                            el.style.display = 'none'           
                        } else {             
                            el.parentNode.removeChild(el)           
                        }         
                    }             
                }            
                   
                
            },     
        })   
    }, 
}
